//**** Defines used to model the castling Moves. **** (define "HasNeverMoved" (= (state at:(mapEntry #1 (mover))) 1) ) (define "PieceHasMoved" (set State at:#1 0) ) (define "RememberPieceHasMoved" (then (and (if (= (state at:(last To)) 1) ("PieceHasMoved" (last To)) ) (set Value at:(last To) (% (+ (value Piece at:(last To)) 1) 2)) ) ) ) (define "KingNotCheckedAndToEmpty" (and (is Empty (to)) (not ("IsInCheck" "King" Mover at:(to))) ) ) (define "DecideToCastle" (do (set Value at:(mapEntry #1 (mover)) (% (+ (value Piece at:(mapEntry #1 (mover))) 1) 2)) next:(move Slide (from (mapEntry #1 (mover))) #2 (between (exact #3) if:#4 ) (to if:True (apply ("PieceHasMoved" (from))) ) #5 ) ) ) (define "CastleRook" (do (set Value at:(mapEntry #1 (mover)) (% (+ (value Piece at:(mapEntry #1 (mover))) 1) 2)) next:(slide (from (mapEntry #1 (mover))) #2 (between (exact #3) if:#4 ) (to if:True (apply ("PieceHasMoved" (from))) ) ) ) ) (define "SmallCastling" ("DecideToCastle" "King" E 2 "KingNotCheckedAndToEmpty" (then ("CastleRook" "RookRight" W 2 True))) ) (define "BigCastling" ("DecideToCastle" "King" W 2 "KingNotCheckedAndToEmpty" (then ("CastleRook" "RookLeft" E 3 True))) ) (define "Castling" (if (and ("HasNeverMoved" "King") (not ("IsInCheck" "King" Mover)) ) (or (if (and ("HasNeverMoved" "RookLeft") (can Move ("CastleRook" "RookLeft" E 3 (or (is Empty (between)) (!= (value Piece at:(from)) (value Piece at:(between))) ))) ) "BigCastling" ) (if (and ("HasNeverMoved" "RookRight") (can Move ("CastleRook" "RookRight" W 2 (or (is Empty (between)) (!= (value Piece at:(from)) (value Piece at:(between))) ))) ) "SmallCastling" ) ) ) ) //**** Defines used to model the Pawn moves. **** (define "DoubleStep" (move Slide Forward (between (exact 2) if:(or (is Empty (between)) (!= (value Piece at:(from)) (value Piece at:(between))) ) ) (to if:(is Empty (to)) (apply if:(is Empty (to)) ) ) ) ) (define "CaptureForwardDiagonal" (move Step (directions {FR FL}) (to if:(and ("IsEnemyAt" (to)) (= (value Piece at:(from)) (value Piece at:(to))) ) (apply (remove (to))) ) ) ) //**** Defines used to model the capture effect. **** (define "CaptureToPieceAndResetCounter" (apply if: (or (and ("IsEnemyAt" (to)) (= (value Piece at:(from)) (value Piece at:(to)))) (is Empty (to))) (if (and ("IsEnemyAt" (to)) (= (value Piece at:(from)) (value Piece at:(to))) ) (remove (to) (then (set Counter)) ) ) ) ) //------------------------------------------------------------------------------ (game "Alice Chess" ("TwoPlayersNorthSouth") (equipment { (board (square 8)) (piece "Pawn" Each (or { (if (is In (from) (sites Start (piece (what at:(from))))) "DoubleStep" ) "StepForwardToEmpty" "CaptureForwardDiagonal" } (then (and { (if (is In (last To) (sites Mover "Promotion")) (moveAgain) ) (set Counter) (set Value at:(last To) (% (+ (value Piece at:(last To)) 1) 2)) }) ) ) ) (piece "Rook" Each (move Slide Orthogonal (between if:(or (is Empty (between)) (!= (value Piece at:(from)) (value Piece at:(between))) ) ) (to if:(and ("IsEnemyAt" (to)) (= (value Piece at:(from)) (value Piece at:(to)))) "CaptureToPieceAndResetCounter" ) "RememberPieceHasMoved" ) ) (piece "King" Each (move Step (to if:(and (not ("IsFriendAt" (to))) (or (is Empty (to)) (= (value Piece at:(from)) (value Piece at:(to))))) "CaptureToPieceAndResetCounter" ) "RememberPieceHasMoved" ) ) (piece "Bishop" Each (move Slide Diagonal (between if:(or (is Empty (between)) (!= (value Piece at:(from)) (value Piece at:(between))) ) ) (to if:(and ("IsEnemyAt" (to)) (= (value Piece at:(from)) (value Piece at:(to)))) "CaptureToPieceAndResetCounter" ) (then (set Value at:(last To) (% (+ (value Piece at:(last To)) 1) 2)) ) ) ) (piece "Knight" Each (move Leap "KnightWalk" (to if:(and (not ("IsFriendAt" (to))) (or (is Empty (to)) (= (value Piece at:(from)) (value Piece at:(to))))) "CaptureToPieceAndResetCounter" ) (then (set Value at:(last To) (% (+ (value Piece at:(last To)) 1) 2)) ) ) ) (piece "Queen" Each (move Slide (between if:(or (is Empty (between)) (!= (value Piece at:(from)) (value Piece at:(between))) ) ) (to if:(and ("IsEnemyAt" (to)) (= (value Piece at:(from)) (value Piece at:(to)))) "CaptureToPieceAndResetCounter" ) (then (set Value at:(last To) (% (+ (value Piece at:(last To)) 1) 2)) ) ) ) (map "King" {(pair 1 "E1") (pair 2 "E8")}) (map "RookLeft" {(pair 1 "A1") (pair 2 "A8")}) (map "RookRight" {(pair 1 "H1") (pair 2 "H8")}) (regions "Promotion" P1 (sites Top)) (regions "Promotion" P2 (sites Bottom)) }) (rules (start { (place "Pawn1" (sites Row 1)) (place "Pawn2" (sites Row 6)) (place "Rook1" {"A1" "H1"} state:1) (place "Knight1" {"B1" "G1"}) (place "Bishop1" {"C1" "F1"}) (place "Queen1" coord:"D1") (place "King1" coord:"E1" state:1) (place "Rook2" {"A8" "H8"} state:1) (place "Knight2" {"B8" "G8"}) (place "Bishop2" {"C8" "F8"}) (place "Queen2" coord:"D8") (place "King2" coord:"E8" state:1) }) (play (if "SameTurn" (do (set Var "promotedValue" (value Piece at:(last To))) next:(move Promote (last To) (piece {"Queen" "Knight" "Bishop" "Rook"}) Mover (then (set Value at:(last To) (var "promotedValue"))) ) ) (do (or (forEach Piece) ("Castling") ) ifAfterwards:(not ("IsInCheck" "King" Mover)) ) ) ) (end { ("Checkmate" "King") (if (or (no Moves Mover) (= (counter) 99)) (result Mover Draw)) }) ) ) //------------------------------------------------------------------------------ (metadata (info { (description "Pieces move the same as they do in standard chess, but a piece transfers at the completion of its move to the opposite board.") (rules "A move in Alice chess has two basic stipulations: the move must be legal on the board on which it is played, and the square transferred to on the opposite board must be vacant. (Consequently, capture is possible only on the board upon which a piece currently stands). The en passant rule is removed.") (id "1667") (source "Wikipedia") (version "1.3.12") (classification "board/war/replacement/checkmate/chess") (author "Vernon Rylands Parton") (credit "Matthew Stephenson") (date "1953") } ) (graphics { (piece Colour P1 value:1 fillColour:(colour 163 189 229)) (piece Colour P2 value:1 fillColour:(colour 146 14 94)) (show Check "King") (piece Scale "Pawn" 0.825) (piece Families {"Defined" "Microsoft" "Pragmata" "Symbola"}) (board Style Chess) }) (ai "Alice Chess_ai" ) )